﻿using System.Collections.Specialized;
using EPiServer;
using EPiServer.Core.Html;

namespace EPiSugar.Content
{
    public static class StringExtensions
    {
        public static bool HasValue(this string value)
        {
            return !string.IsNullOrEmpty(value);
        }

        public static string Format(this string format, params object[] args)
        {
            return string.Format(format, args);
        }

        public static string AppendQuery(this string url, string name, string value)
        {
            return UriSupport.AddQueryString(url, name, value);
        }

        public static string AppendQuery(this string url, NameValueCollection parameters)
        {
            foreach (string key in parameters.AllKeys)
            {
                url = url.AppendQuery(key, parameters[key]);
            }
            return url;
        }

        public static string StripHtml(this string text, int length)
        {
            if (length <= 0)
                return null;

            return TextIndexer.StripHtml(text, length);
        }
    }
}